export const dase = {
    data () {
        return {
          module:'users',
        

            operdatamodel :false,
           
            data: [
            ],
            total:0,
            pageSize:10,
            page:1,
            name:'',
           ids:[],
           id:{}
        }
         
    },
    methods: {
        
        remove (params) {
             this.$Modal.confirm({
                title: '确认删除',
                content: '<p>你确认删除该数据吗？</p>',
                onOk: () => {
                    this.$Message.info('删除成功');
                this.axios({
                    url:`http://localhost:3000/${this.module}/data/${params.row._id}`,
                    method:'delete'
                }).then(res=>{
                    this.$Message.info('删除数据成功')
                    this.getpage();
                })

                },
                onCancel: () => {
                    this.$Message.info('取消删除');
                }
            });
          
        },
        getpage(){
                   this.axios({
                    url:`http://localhost:3000/${this.module}/list`,
                    method:'post',
                    data:{
                        rows:this.pageSize,
                        page:this.page,
                        name :this.name
                    }
                }).then(res=>{
                  
                    this.data=res.data.docs;
                    this.total=res.data.total;
                })
        },
        onchange(page){
            this.page=page;
               this.getpage()
        },
         changeon(qq){
           this.pageSize=qq;
             this.getpage()
       },
       onselectionchange(selection){
        var ids=[];
        for(let i=0;i<selection.length;i++){
            ids.push(selection[i]._id)
        }
           this.ids=ids;
       },
        removes(){

              this.$Modal.confirm({
                title: '确认删除',
                content: '<p>你确认删除该数据吗？</p>',
                onOk: () => {
                  
                  this.axios({
                        url:`http://localhost:3000/${this.module}/removes`,
                         method:'post',
                        data:{
                            ids:this.ids.toString(),
                           
                        }
                        
                        }).then(res=>{
                         this.$Message.info('删除数据成功')
                         this.getpage(); 
                       })

                },
                onCancel: () => {
                    this.$Message.info('取消删除');
                }
            });


          
       },
        search(value){
           this.axios({
                    url:`http://localhost:3000/${this.module}/list`,
                    method:'post',
                    data:{
                        rows:this.pageSize,
                        page:this.page,
                        name :this.name
                    }
                }).then(res=>{
                 
                    this.data=res.data.docs;
                  
                })
        },
      Operdata(){
        this.operdatamodel=true;
      },
       edidata(params){
          this.axios({
              url:`http://localhost:3000/${this.module}/data/${params.row._id}`,
              method:'get',
          }).then(res=>{
             this.formValidate=res.data;
             this.operdatamodel=true;
             this.id=params.row._id
          })
       } ,
     handleSubmit (name) {
            this.$refs[name].validate((valid) => {
                if (valid) {
                        if(this.id!==0){
                          this.axios({
                              url:`http://localhost:3000/${this.module}/data/${this.id}`,
                              method:'put',
                              data:this.formValidate
                          }).then(res=>{
                                this.$Message.success('数据操作成功');
                                this.operdatamodel =false;
                               
                                this.id=0;
                          })
                        }else{
                            
                        }
                    this.axios({
                        
                        url:`http://localhost:3000/${this.module}/data`,
                        method:'post',
                        data:this.formValidate
                    }).then(res=>{
                     
                    })
                     this.$Message.success('数据操作成功');
                     this.operdatamodel =false;
                     this.getpage();
                } else {
                    this.$Message.error('Fail!');
                }
            })
        },
        handleReset (name) {
            this.$refs[name].resetFields();
        }
    
      
    },
  mounted() {
       this.getpage()
  },

        
        

}